/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.logging;


import java.util.List;
import java.util.Map;

import org.apache.struts2.config.Result;
import org.jaxson.struts.BaseAction;
import org.jaxson.struts.reverseAjax.ReverseAjaxManager;


/**
 * Struts action to handle loggin configuration changes.
 * Changes are pushed back to clients via reverse ajax.
 * 
 * @author Joe Maisel
 */
@Result(name = "SUCCESS", value = "/admin/logging.jsp")
public class LogConfigurationAction extends BaseAction
{
	private static final long serialVersionUID = 98798722341343298L;

	public LogConfigurationAction ()
	{
		setModel( new LogConfigurationEvent() );
	}

	/**
	 * @see org.jaxson.struts.BaseAction#handle()
	 */
	@Override
	public String handle()
	{
		LogConfigurationEvent evt = (LogConfigurationEvent) model;
		ReverseAjaxManager.addToBatch( session, evt );
		ReverseAjaxManager.commitBatch( session );
		return "SUCCESS";
	}

	
	/**
	 * Used by the admin screen.
	 */
	public Map<Integer, String> getLevels()
	{
		return LogLevel.asMap();
	}

	/**
	 * Used by the admin screen.
	 */
	public List<Integer> getBatchSizes()
	{
		java.util.List<Integer> sizes = new java.util.ArrayList<Integer>();

		for( int i = 0; i < 100; )
		{
			sizes.add( ++i );
		}

		return sizes;
	}

}
